Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BASE_URL environment configuration #529

Closed
wants to merge 2 commits into from

Conversation

dodo920306
Copy link
Contributor

@dodo920306 dodo920306 commented Sep 19, 2024

Make API URL also relative and insert BASE_URL into Nginx configuration so that it can fully work with proxies.

One can create Ivory container by a command like docker run -d -e BASE_URL="/ivory" -p 80:80 --restart unless-stopped aelsergeev/ivory to make it work under /ivory or any other give url. It can also still works even if the variable hasn't been assigned, but once it's assigned, it must start with a slash '/'.

Notice that nginx.conf has been changed to rewrite the api request path, which causes it now can't be used directly without envsubst.

@@ -9,6 +9,13 @@ nginx -v
export GIN_MODE=release
/opt/service/ivory &

# insert base url
envsubst '\$BASE_URL' < /etc/nginx/nginx.conf > "/etc/nginx/nginx.conf.tmp" && mv "/etc/nginx/nginx.conf.tmp" "/etc/nginx/nginx.conf"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, I don't like this solution, I was checking as well how to do it better, the main problem that nginx doesn't work with env variables, I want to check if there is more elegant way to do this. I'm even thinking changing nginx 😂

Copy link
Contributor Author

@dodo920306 dodo920306 Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understand. It's a little bit awkward, but even Nginx themself use envsubst in their images.
Anyway, I'm also wondering if there is a better solution🤔.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and there is one more problem that even when we have relative path in html, it doesn't work properly with trailing slash, to work it correctly we need to add <base> element with this url. I'm trying to do it right now will see. I will share the changes with a bit later today probably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't work properly with trailing slash

I don't get it, but I guess I'll see it in the changes👍.

Copy link
Contributor

@anselvo anselvo Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to get rid of nginx and use go server, I wanted it to do long time ago, because it will help to ease setup of TLS and usage of http/2. You can check it here #530 I will release it under 1.3.4.

P.S. Thanks for you effort, your comments were useful, it helped me to know something new, hope you as well :)
P.S.S I will close this PR

@anselvo
Copy link
Contributor

anselvo commented Sep 20, 2024

Won't be merge, because of another solution #530

@anselvo anselvo closed this Sep 20, 2024
@dodo920306 dodo920306 deleted the feature/base_url branch September 21, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a customized base URL in the configuration through an environment variable
2 participants